package com.feihao.zhou.controller;


import com.feihao.zhou.domain.Address;
import com.feihao.zhou.domain.User;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServlet;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/userController")
public class UserController {

    @RequestMapping("/say")
    private String say(String name){
        System.out.println("user mvc running");
        System.out.println("参数："+name);
        return "/springMVC.jsp";
    }

    @RequestMapping("/login1")
    private String login(String username,String password){
        if ("zs".equals(username)&& "123".equals(password)){
            return "/success.jsp";
        }
        return "/fail.jsp";
    }

    //-------------request请求参数：--------------
    @RequestMapping("/request1")
    private String request1( @RequestParam("userName") String username){
        System.out.println(username);
        return "/success.jsp";
    }

    @RequestMapping("/request2")
    private String request2( @RequestParam(value = "userName",required = false) String username){
        System.out.println(username);
        return "/success.jsp";
    }

    @RequestMapping("/request3")
    private String request3(User user,int age1){
        System.out.println(user+","+age1);
        return "/success.jsp";
    }

    @RequestMapping("/request4")
    private String request4(User user){
        System.out.println(user.getAddress());
        return "/success.jsp";
    }


    @RequestMapping("/request5")
    private String request5(String str[]){
        System.out.println(Arrays.toString(str));
        return "/success.jsp";
    }

    @RequestMapping("/request6")
    private String request6(@RequestParam("list") List<String> list){
        System.out.println(list);
        return "/success.jsp";
    }
    @RequestMapping("/request7")
    private String request7( @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss:SSS") Date date){
        System.out.println(date);
        return "/success.jsp";
    }



    @RequestMapping("/request8")
    private ModelAndView request8(ModelAndView modelAndView){
        User user = new User("小三",33,new Address("长沙","湖南省"));
        modelAndView.addObject("user",user);
        modelAndView.setViewName("forward:/page.jsp");
        return modelAndView;
    }



    @RequestMapping("/request9")
    @ResponseBody
    private User request9(){
        User user = new User("小三",33,new Address("长沙","湖南省"));
        return user;
    }



}
